<!--
 * @Descripttion: (达因抽检记录/cks_basketrecord)
 * @Author: (admin)
 * @Date: (2025-02-22)
-->
<template>
    <div>
      <el-form :model="queryParams" label-position="right" inline ref="queryRef" v-show="showSearch" @submit.prevent>
        
        <el-form-item :label="$t('mes.blueCode')" prop="blueCode"> 
          <!-- 请输入子篮码 -->
            <el-input v-model="queryParams.blueCode" placeholder="" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item :label="$t('mes.type')" prop="Type">
            <el-select v-model="queryParams.Type" placeholder="" clearable style="width: 240px">
              <el-option :label="$t('part_type.type00')" :value="-1" />
              <el-option v-for="dict in dictParams" :key="dict.langKey"
               :label="$t(dict.langKey)" :value="dict.dictValue" />
            </el-select>
          </el-form-item>
        <el-form-item :label="$t('mes.created')">
            <el-date-picker
              v-model="dateRange"
              style="width: 240px"
              type="daterange"
              range-separator="-"
              start-placeholder=""
              end-placeholder=""></el-date-picker>
          </el-form-item>
        <el-form-item>
          <el-button icon="search" type="primary" @click="handleQuery">{{ $t('btn.search') }}</el-button>
          <el-button icon="refresh" @click="resetQuery">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 工具区域 -->
      <el-row :gutter="15" class="mb10">
        <el-col :span="1.5">
          <!-- <el-button type="primary" v-hasPermi="['cksbasketrecord:add']" plain icon="plus" @click="handleAdd">
            {{ $t('btn.add') }}
          </el-button> -->
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>
  
      <el-table
        :data="dataList"
        v-loading="loading"
        ref="table"
        border
        header-cell-class-name="el-table-header-cell"
        highlight-current-row
        @sort-change="sortChange"
        >
       
        <el-table-column prop="blueCode" :label="$t('mes.blueCode')" align="center" :show-overflow-tooltip="true" v-if="columns.showColumn('blueCode')"/>
        <el-table-column prop="type" :label="$t('mes.blueType')" align="center" v-if="columns.showColumn('type')">
          <template #default="scope">
            <dict-tag :options=" options.typeOptions" :value="scope.row.type"  />
          </template>
        </el-table-column>
        <el-table-column prop="checkTime" :label="$t('mes.checkTime')" :show-overflow-tooltip="true"  v-if="columns.showColumn('checkTime')"/>
        <el-table-column prop="checkResult" :label="$t('mes.checkResult')" align="center" v-if="columns.showColumn('checkResult')"/>
        <el-table-column prop="createdTime" :label="$t('mes.createdTime')" :show-overflow-tooltip="true"  v-if="columns.showColumn('createdTime')"/>
        <!-- <el-table-column prop="isDeleted" label="IsDeleted" align="center" v-if="columns.showColumn('isDeleted')">
          <template #default="scope">
            <dict-tag :options=" options.isDeletedOptions" :value="scope.row.isDeleted"  />
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="操作" width="160">
          <template #default="scope">
            <el-button type="success" size="small" icon="edit" title="编辑" v-hasPermi="['cksbasketrecord:edit']" @click="handleUpdate(scope.row)"></el-button>
            <el-button type="danger" size="small" icon="delete" title="删除" v-hasPermi="['cksbasketrecord:delete']" @click="handleDelete(scope.row)"></el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  
  
      <!-- 添加或修改子篮记录对话框 -->
      <el-dialog :title="title" :lock-scroll="false" v-model="open" >
        <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
          <el-row :gutter="20">
              
            <el-col :lg="12">
              <el-form-item label="Id" prop="id">
                <el-input v-model.number="form.id" placeholder="请输入Id" :disabled="opertype != 1"/>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="DCId" prop="dCId">
                <el-input v-model="form.dCId" placeholder="请输入DCId" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="子篮码" prop="blueCode">
                <el-input v-model="form.blueCode" placeholder="请输入子篮码" />
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="子篮类型" prop="type">
                <el-select v-model="form.type"  placeholder="请选择子篮类型">
                  <el-option
                    v-for="item in options.typeOptions" 
                    :key="item.dictValue" 
                    :label="item.dictLabel" 
                    :value="parseInt(item.dictValue)"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="清洗上传时间" prop="checkTime">
                <el-date-picker v-model="form.checkTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
              
            <el-col :lg="12">
              <el-form-item label="检测结果" prop="checkResult">
                <el-input v-model.number="form.checkResult" placeholder="请输入检测结果" />
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="创建时间(子篮上料时间)" prop="createdTime">
                <el-date-picker v-model="form.createdTime" type="datetime" :teleported="false" placeholder="选择日期时间"></el-date-picker>
              </el-form-item>
            </el-col>
  
            <el-col :lg="12">
              <el-form-item label="IsDeleted" prop="isDeleted">
                <el-radio-group v-model="form.isDeleted">
                  <el-radio v-for="item in options.isDeletedOptions" :key="item.dictValue" :value="item.dictValue">
                    {{item.dictLabel}}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <template #footer v-if="opertype != 3">
          <el-button text @click="cancel">{{ $t('btn.cancel') }}</el-button>
          <el-button type="primary" @click="submitForm">{{ $t('btn.submit') }}</el-button>
        </template>
      </el-dialog>
    </div>
  </template>
  
  <script setup name="CksBasketrecord">
  import { listCksBasketrecord,
   addCksBasketrecord, delCksBasketrecord, 
   updateCksBasketrecord,getCksBasketrecord, 
   } 
  from '@/api/business/cksbasketrecord.js'
  const { proxy } = getCurrentInstance()
  const ids = ref([])
  const loading = ref(false)
  const showSearch = ref(true)
  const dateRange = ref([])
  const queryParams = reactive({
    pageNum: 1,
    pageSize: 10,
    sort: '',
    sortType: 'asc',
    blueCode:'',

  })
  const columns = ref([
    { visible: true, prop: 'id', label: 'Id' },
    { visible: true, prop: 'dCId', label: 'DCId' },
    { visible: true, prop: 'blueCode', label: '子篮码' },
    { visible: true, prop: 'type', label: '子篮类型' },
    { visible: true, prop: 'checkTime', label: '清洗上传时间' },
    { visible: true, prop: 'checkResult', label: '检测结果' },
    { visible: true, prop: 'createdTime', label: '创建时间(子篮上料时间)' },
    { visible: true, prop: 'isDeleted', label: 'IsDeleted' },
  ])
  const total = ref(0)
  const dataList = ref([])
  const queryRef = ref()
  const defaultTime = ref([new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 2, 1, 23, 59, 59)])
  
  

  const dictParams = ref([])
proxy.getDicts('cks_part_type').then((response) => {
    dictParams.value = response.data
})
  function getList(){
    loading.value = true
    const queryPara = proxy.addDateRange(queryParams, dateRange.value)
    console.log(queryPara);
    listCksBasketrecord(queryPara).then(res => {
      const { code, data } = res
      if (code == 200) {
        dataList.value = data.result
        total.value = data.totalNum
        loading.value = false
      }
    })
  }
  
  // 查询
  function handleQuery() {
    queryParams.pageNum = 1
    getList()
  }
  
  // 重置查询操作
  function resetQuery(){

    proxy.resetForm("queryRef")
    dateRange.value = []
    handleQuery()
  }
  // 自定义排序
  function sortChange(column) {
    var sort = undefined
    var sortType = undefined
  
    if (column.prop != null && column.order != null) {
      sort = column.prop
      sortType = column.order
  
    }
    queryParams.sort = sort
    queryParams.sortType = sortType
    handleQuery()
  }
  
  /*************** form操作 ***************/
  const formRef = ref()
  const title = ref('')
  // 操作类型 1、add 2、edit 3、view
  const opertype = ref(0)
  const open = ref(false)
  const state = reactive({
    single: true,
    multiple: true,
    form: {},
    rules: {
      id: [{ required: true, message: "Id不能为空", trigger: "blur"    , type: "number"  }],
      dCId: [{ required: true, message: "DCId不能为空", trigger: "blur"     }],
      createdTime: [{ required: true, message: "创建时间(子篮上料时间)不能为空", trigger: "blur"     }],
      isDeleted: [{ required: true, message: "IsDeleted不能为空", trigger: "blur"     }],
    },
    options: {
      // 子篮类型 选项列表 格式 eg:{ dictLabel: '标签', dictValue: '0'}
  typeOptions: []
  //{ 1:'翅片',2:'盖板',3:'底板',4:'大焊环',5:'小焊环'  },
    }
  })
  proxy.getDicts('cks_part_type').then((response) => {
    state.options.typeOptions = response.data
})
  const { form, rules, options, single, multiple } = toRefs(state)
  
  // 关闭dialog
  function cancel(){
    open.value = false
    reset()
  }
  
  // 重置表单
  function reset() {
    form.value = {
      id: null,
      dCId: null,
      blueCode: null,
      type: null,
      checkTime: null,
      checkResult: null,
      createdTime: null,
      isDeleted: null,
    };
    proxy.resetForm("formRef")
  }
  
  
  // 添加按钮操作
  function handleAdd() {
    reset();
    open.value = true
    title.value = '添加子篮记录'
    opertype.value = 1
  }
  // 修改按钮操作
  function handleUpdate(row) {
    reset()
    const id = row.id || ids.value
    getCksBasketrecord(id).then((res) => {
      const { code, data } = res
      if (code == 200) {
        open.value = true
        title.value = '修改子篮记录'
        opertype.value = 2
  
        form.value = {
          ...data,
        }
      }
    })
  }
  
  // 添加&修改 表单提交
  function submitForm() {
    proxy.$refs["formRef"].validate((valid) => {
      if (valid) {
  
        if (form.value.id != undefined && opertype.value === 2) {
          updateCksBasketrecord(form.value).then((res) => {
            proxy.$modal.msgSuccess("修改成功")
            open.value = false
            getList()
          })
        } else {
          addCksBasketrecord(form.value).then((res) => {
              proxy.$modal.msgSuccess("新增成功")
              open.value = false
              getList()
            })
        }
      }
    })
  }
  
  // 删除按钮操作
  function handleDelete(row) {
    const Ids = row.id || ids.value
  
    proxy
      .$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？', "警告", {
        confirmButtonText: proxy.$t('common.ok'),
        cancelButtonText: proxy.$t('common.cancel'),
        type: "warning",
      })
      .then(function () {
        return delCksBasketrecord(Ids)
      })
      .then(() => {
        getList()
        proxy.$modal.msgSuccess("删除成功")
      })
  }
  
  
  
  
  
  handleQuery()
  </script>